/**
 * 座位管理管理初始化
 */
var TrainSeat = {
    id: "TrainSeatTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    vehicleId: $("#vehicleId").val()
};

/**
 * 初始化表格的列
 */
TrainSeat.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        /*{title: '车辆id', field: 'vehicleId', visible: true, align: 'center', valign: 'middle'},*/
        {title: '车次', field: 'vehicleNo', visible: true, align: 'center', valign: 'middle'},
        {title: '车厢号', field: 'carriageNo', visible: true, align: 'center', valign: 'middle'},
        {title: '座位号', field: 'seatNo', visible: true, align: 'center', valign: 'middle'},
        {title: '座位类型', field: 'seatType', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
TrainSeat.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        TrainSeat.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加座位管理
 */
TrainSeat.openAddTrainSeat = function () {
    var index = layer.open({
        type: 2,
        title: '添加座位管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/trainSeat/trainSeat_add/'+TrainSeat.vehicleId
    });
    this.layerIndex = index;
};

/**
 * 打开查看座位管理详情
 */
TrainSeat.openTrainSeatDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '座位管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/trainSeat/trainSeat_update/' + TrainSeat.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除座位管理
 */
TrainSeat.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/trainSeat/delete", function (data) {
            Feng.success("删除成功!");
            TrainSeat.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("trainSeatId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询座位管理列表
 */
TrainSeat.search = function () {
    var queryData = {};
    queryData['carriageNo'] = $("#carriageNo").val();
    queryData['seatNo'] = $("#seatNo").val();
    queryData['seatType'] = $("#seatType").val();
    TrainSeat.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = TrainSeat.initColumn();
    var table = new BSTable(TrainSeat.id, "/trainSeat/list/"+TrainSeat.vehicleId, defaultColunms);
    //table.setPaginationType("client");
    TrainSeat.table = table.init();
});
